using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Data.OleDb;
using System.IO;

namespace CrmDocman.Common {
    public class DatabaseMan {
        private SqlConnection conDb;
        public DatabaseMan() {
            conDb = new SqlConnection();
        }
        public bool ConnectToDatabase(string mserName, string mDbName) {
            if(conDb.State == ConnectionState.Open)
                conDb.Close();
            string s;
            s = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" + mDbName +
                ";Data Source=" + mserName + ";Packet Size=4096;";
            conDb.ConnectionString = s;
            try {
                conDb.Open();
                return true;
            } catch(SqlException) {
                return false;
            }
        }
        public bool ConnectToDatabase(string mserName, string mDbName, string mUserName, string mPass) {
            if(conDb.State == ConnectionState.Open)
                conDb.Close();
            string s;
            s = "Initial Catalog={0};Data Source={1};uid = {2}; password = {3};Packet Size=4096;";
            conDb.ConnectionString = string.Format(s, mserName, mDbName, mUserName, mPass);
            try {
                conDb.Open();
                return true;
            } catch(SqlException ex) {
                return false;
            }
        }
    }
}
